if (!("RORTICUS" in window)) {
    RORTICUS = {};
}
RORTICUS.Slider = function (c)
{
    this.element = c;
    this.min = 0;
    this.max = 100;
    this.value = 0;
    this.callback = null;
    this.baseColor = "#aaa";
    try
    {
        if (c.getAttribute("minimum")) {
            var m = parseInt(c.getAttribute("minimum"));
            if (!isNaN(m)) {
                this.min = m;
            }
        }
        if (c.getAttribute("maximum")) {
            var m = parseInt(c.getAttribute("maximum"));
            if (!isNaN(m)) {
                this.max = m;
            }
        }
        if (c.getAttribute("onslide")) {
            this.callback = new Function("value", c.getAttribute("onslide"));
        }
        var f = parseInt(c.value);
        if (!isNaN(f)) {
            this.value = f;
        }
        if (c.getAttribute("color")) {
            this.baseColor = c.getAttribute("color");
        }
    }
    catch (v) {}
    var o = {};
    try
    {
        if (this.baseColor.substring(0, 1) == "#") {
            this.baseColor = this.baseColor.substring(1);
        }
        if (this.baseColor.length == 3)
        {
            var j = this.baseColor.substring(0, 1);
            var s = this.baseColor.substring(1, 2);
            var w = this.baseColor.substring(2);
            j = j + j;
            s = s + s;
            w = w + w;
        }
        else
        {
            if (this.baseColor.length == 6)
            {
                var j = this.baseColor.substring(0, 2);
                var s = this.baseColor.substring(2, 4);
                var w = this.baseColor.substring(4);
            }
            else {
                throw "unrecognized color";
            }
        }
        var i = parseInt(j, 16);
        var t = parseInt(s, 16);
        var d = parseInt(w, 16);
        o = {
            r : i, g : t, b : d
        };
    }
    catch (v) {
        o = {
            r : 170, g : 170, b : 170
        };
    }
    function u(B, C)
    {
        if (!C) {
            C = 1;
        }
        var A = Math.floor(B.r * C);
        var z = Math.floor(B.g * C);
        var e = Math.floor(B.b * C);
        var y = "#";
        var x = A.toString(16);
        if (x.length == 1) {
            y += "0" + x;
        }
        else {
            y += x;
        }
        var x = z.toString(16);
        if (x.length == 1) {
            y += "0" + x;
        }
        else {
            y += x;
        }
        var x = e.toString(16);
        if (x.length == 1) {
            y += "0" + x;
        }
        else {
            y += x;
        }
        return y;
    }
    this.barColor = u(o);
    this.sliderColor = u(o, 0.66);
    if (c.parentNode)
    {
        var k = this;
        this.sliderElement = document.createElement("DIV");
        this.sliderElement.style.width = c.offsetWidth + "px";
        this.sliderElement.style.height = c.offsetHeight + "px";
        var q = document.createElement("DIV");
        q.style.width = (c.offsetWidth - 6) + "px";
        q.style.height = "3px";
        q.style.fontSize = "1px";
        q.style.backgroundColor = this.barColor;
        q.style.position = "relative";
        q.style.top = (c.offsetHeight / 2 - 3 / 2) + "px";
        q.style.left = "3px";
        q.style.border = "1px inset gray";
        this.sliderElement.onmousedown = function (b)
        {
            if (!b) {
                b = window.event;
            }
            b.cancelBubble = true;
            k.startDragSlider();
            k.dragEvent(b);
            return false;
        };
        this.sliderElement.appendChild(q, true);
        var n = document.createElement("DIV");
        n.style.position = "relative";
        n.style.width = "6px";
        n.style.height = "12px";
        n.style.fontSize = "1px";
        n.style.backgroundColor = this.sliderColor;
        n.style.top = (c.offsetHeight / 2 - 12 / 2 - 3) + "px";
        n.style.cursor = "pointer";
        n.style.border = "1px outset gray";
        n.onmousedown = function (b)
        {
            if (!b) {
                b = window.event;
            }
            b.cancelBubble = true;
            k.startDragSlider();
            return false;
        };
        this.slider = n;
        this.bar = q;
        this.sliderElement.appendChild(n, true);
        c.parentNode.insertBefore(this.sliderElement, c);
        c.style.visibility = "hidden";
        c.style.position = "absolute";
        var l = n.offsetHeight;
        var a = n.offsetWidth;
        var h = q.offsetWidth;
        var p = q.offsetHeight;
        this.sliderWidth = a;
        q.style.top = (c.offsetHeight / 2 - p / 2) + "px";
        q.style.left = (a / 2) + "px";
        q.style.width = (c.offsetWidth - a / 2) + "px";
        n.style.top = (c.offsetHeight / 2 - l / 2 - p) + "px";
        this.calculationWidth = h;
        this.positionSliderToValue();
    }
};
RORTICUS.InitSliders = function ()
{
    var b = document.getElementsByTagName("INPUT");
    for (var d = 0; d < b.length; d++)
    {
        var c = b[d];
        var e = c.getAttribute("_type");
        if (e && e == "slider") {
            var a = new RORTICUS.Slider(c);
        }
    }
};
RORTICUS.Slider.prototype.positionSliderToValue = function ()
{
    var a = Math.floor(this.calculationWidth * ((this.value - this.min) / (this.max - this.min)));
    this.slider.style.left = (a) + "px";
};
RORTICUS.Slider.prototype.startDragSlider = function ()
{
    var a = this;
    function b(d)
    {
        return a.dragEvent(d);
    }
    function c(d)
    {
        if (!d) {
            d = window.event;
        }
        d.cancelBubble = true;
        if ("addEventListener" in document)
        {
            document.removeEventListener("mousemove", b, false);
            document.removeEventListener("mouseup", c, false);
        }
        else {
            document.detachEvent("onmousemove", b);
            document.detachEvent("onmouseup", b);
        }
    }
    if ("addEventListener" in document)
    {
        document.addEventListener("mousemove", b, false);
        document.addEventListener("mouseup", c, false);
    }
    else {
        document.attachEvent("onmousemove", b);
        document.attachEvent("onmouseup", c);
    }
};
RORTICUS.Slider.prototype.dragEvent = function (c)
{
    if (!c) {
        c = window.event;
    }
    c.cancelBubble = true;
    var e = {
        x : c.clientX + document.body.scrollLeft, y : c.clientY + document.body.scrollTop
    };
    var b = 
    {
        left : function (f)
        {
            return (f) ? (((f.offsetLeft) ? f.offsetLeft : 0) + arguments.callee(f.offsetParent)) : 0;
        }
        (this.sliderElement),
        top : function (f)
        {
            return (f) ? (((f.offsetTop) ? f.offsetTop : 0) + arguments.callee(f.offsetParent)) : 0;
        }
        (this.sliderElement), width : this.calculationWidth, height : this.sliderElement.offsetHeight
    };
    var a = e.x - b.left;
    if (a < 0) {
        a = 0;
    }
    if (a > b.width) {
        a = b.width;
    }
    var d = Math.round((a / b.width) * (this.max - this.min) + this.min);
    this.value = d;
    this.element.value = d;
    if (this.callback) {
        this.callback(d);
    }
    this.positionSliderToValue();
    if ("preventDefault" in c) {
        c.preventDefault();
    }
    else {
        c.returnValue = false;
    }
    return false;
};
if ("addEventListener" in window) {
    window.addEventListener("load", function ()
    {
        RORTICUS.InitSliders();
    }, false);
}
else {
    window.attachEvent("onload", function ()
    {
        RORTICUS.InitSliders();
    });
}
